package com.xxjqr.rbac.config;

import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;



//@Component
//public class CORSFilter implements Filter {
//
//    private final List<String> allowedOrigins = Arrays.asList("http://localhost:8080","http://localhost:8082");// 允许跨域的地址
//
//
//    @Override
//    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
//        HttpServletResponse response = (HttpServletResponse) servletResponse;
//        HttpServletRequest request = (HttpServletRequest) servletRequest;
//
//        response.setHeader("Access-Control-Allow-Headers", "X-Requested-With, Accept, Content-Type");
//        response.setHeader("Access-Control-Allow-Methods", "GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH");
//        String origin = request.getHeader("Origin");
//        response.setHeader("Access-Control-Allow-Origin", allowedOrigins.contains(origin) ? origin : "");
//        // 是否允许浏览器携带用户身份信息（cookie）
//        response.setHeader("Access-Control-Allow-Credentials","true");
//        // 图片上传会用到
//        if( "OPTIONS".equals(request.getMethod())){
//        }
//        filterChain.doFilter(servletRequest, servletResponse);
//    }
//
//    @Override
//    public void destroy() {
//    }
//
//    @Override
//    public void init(FilterConfig filterConfig) throws ServletException {
//    }
//}